<template>
  <div class="pagination">
    <span :disabled="pages === 1" @click="prev"> &lt; </span>
    <span>{{ pages + "/" + total }}</span>
    <span :disabled="pages === total" @click="next"> > </span>
  </div>
</template>
<!--  -->
<script>
import { mapMutations, mapState } from "vuex";
export default {
  name: "Pagination",
  // 收集 vuex中的数据
  // data() {
  //   return {
  //     totals: this.total,
  //     pages: this.page,
  //     pageSizes: this.pageSize,
  //   };
  // },
  props: {
    total: {
      type: Number,
      default: 3,
    },
    page: {
      type: Number,
      default: 1,
    },
    pageSize: {
      type: Number,
      default: 10,
    },
  },
  computed:{
    ...mapState("page", ["pages"]),
  },
  methods: {
    ...mapMutations("page", ["ChangeCurrentPage"]),
    prev() {
      if (this.pages === 1) {
        return;
      }
      this.ChangeCurrentPage(this.pages - 1);
    },
    next() {
      if (this.pages === this.total) {
        return;
      }
      this.ChangeCurrentPage(this.pages + 1);
    },
  },
};
</script>

<style lang="less" scoped>
.pagination {
  text-align: center;
  button {
    margin: 0 5px;
    background-color: #f4f4f5;
    color: #606266;
    outline: none;
    border-radius: 2px;
    padding: 0 4px;
    vertical-align: top;
    display: inline-block;
    font-size: 13px;
    min-width: 35.5px;
    height: 28px;
    line-height: 28px;
    cursor: pointer;
    box-sizing: border-box;
    text-align: center;
    border: 0;

    &[disabled] {
      color: #c0c4cc;
      cursor: not-allowed;
    }

    &.active {
      cursor: not-allowed;
      background-color: #409eff;
      color: #fff;
    }
  }
}
</style>
